function hideDiv(div_id) {
	$("#" + div_id).animate({
		opacity : "hide"
	}, 300);
}
function popupDiv(div_id) {
	var div_obj = $("#" + div_id);
	//窗口宽度,高度
	var winWidth = $(window).width();
	var winHeight = $(window).height();
	//弹出的div的宽度,高度
	var popHeight = div_obj.height();
	var popWidth = div_obj.width();
	div_obj.animate({
		opacity : "show",
		left : (winWidth - popWidth) / 2,
		top : (winHeight - popHeight) / 2,
		width : popWidth,
		height : popHeight
	}, 300);
}
//课程修改的js事件
$(function() {
	$("#UpdateTrainScore_div").easydrag();
	$("#UpdateTrainScore_div").setHandler("#UpdateTrainScore_div #UpdateTrainScore_head");
});

$(function() {
	$("#AddTrainScore_div").easydrag();
	$("#AddTrainScore_div").setHandler("#AddTrainScore_div #AddTrainScore_head");
});

function popadd()
{
	if(!RolePowerManager())
	{
		return;
	}
	popupDiv('AddTrainScore_div');
}


function changePageSize()
{
	var pageSize=$("#pageSize").val();
	location.href="FindTrainScore?pageSize="+pageSize;
}
function search()
{
	$("#searchform").submit();
}
function clickUpdateTrainScore(empid,trainid)
{
	 popupDiv('UpdateTrainScore_div');
	 GetEmpTrainManager.getByEmpIdAndTrainId(empid,trainid,function(data)
	 {
		 $("#empid").val(data.empid);
		 $("#upempname").html(data.empname);
		 $("#upempno").html(data.empno);
		 $("#uptrainid").html(data.trainid);
		 $("#uptrainname").html(data.trainname);
		 for(var i=0;i<data.course.length;i++)
			 {
			 $("[class=upcourse]:last").after("<tr class='addcs' name='addcs' id='addcs'><td>"+data.course[i].coursename+"成绩</td><td>" +
						"<input type='text' name='score' value='"+data.course[i].score+"'/><input type='hidden' name='traincourseid' value='" +data.course[i].traincourseid+
						"'/></td></tr>");									
			 }	
		 $("#sumscore").html(data.sum);
	 });
	
}
function closediv()
{
	
	hideDiv('UpdateTrainScore_div');
	location.href="FindTrainScore";
}
function checkemp()
{	var flag=false;
	$("#emperr").html("");
	TrainCourseManager.ifEmpNoExist($("#empno").val(),function(data)
			{
				if(!data)
					{
						alert("员工不存在");
						$("#emperr").html("员工不存在");
						return false;
					}else
						{
						flag=true;
						}
			});
	return flag;
}
var count=0;
function checktrainid()
{
	var flag=false;
	$(".addcs").remove();
	$("#trainiderr").html("");
	TrainCourseManager.ifTrainIdExist($("#trainid").val(),function(data)
			{
				if(!data)
					{
					alert("培训不存在");
					$("#trainiderr").html("培训不存在");
					
					}else
						{
						flag=true;
						TrainCourseManager.getTrainCourseByTrainId($("#trainid").val(),function(data2)
								{
									count =data2.length;
									for(var i=0;i<data2.length;i++)
										{
										$("[class=addcourse]:last").after("<tr class='addcs' name='addcs' id='addcs'><td>"+data2[i].course.name+"成绩</td><td>" +
													"<input type='text' name='score'/><input type='hidden' name='traincourseid' value='" +data2[i].id+
													"'/></td></tr>");					
											$("#AddTrainScore_div").height($("#AddTrainScore_div").height()  + 38);
										}
								});
						
						}
			});
	return flag;
	
}
function addTrainScore()
{
	/*var score=$("input #addcs");
	alert(score.length);
	for(var i=0;i<score.length;i++)
		{
		
			if(!score[i].value)
				{
				alert("成绩不能为空");
				return;
				}else
					{
					alert("成绩可用");
					}
		}*/
	/*
	alert(checkemp());
	if(checkemp()||checktrainid())
		{
			alert("提交前");
			$("#addAddTrainScoreform").submit();	
		}
	else
			{
			alert("请保持信息的正确性");
			return;
			}
			*/
	$("#addAddTrainScoreform").submit();	
}

function UpdateTrainScore()
{
	if(!RolePowerManager())
	{
		return;
	}
	$("#updatetrainScoreform").submit();
}
function deleteTrainScore(id)
{
	if(!RolePowerManager())
	{
		return;
	}
	if(!confirm("是否确定删除 ？"))
	{
		return;
	}
	CourseScoreManager.deleteById(id,function(data)
			{
				if(data)
					{
					alert("修改成功");
					location.href="FindTrainScore";
					}else{
						alert("删除失败");
					}
			});
}